package cn.edu.dgut.sai.json;

import javax.json.bind.annotation.*;
import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * @author Sai
 * Created by Sai on 2019-03-15.
 * @see JsonbProperty - 用于指定自定义字段名称
 * @see JsonbTransient - 当我们想要在反序列化/序列化期间忽略该字段时
 * @see JsonbDateFormat - 当我们想要定义日期的显示格式时
 * @see JsonbNumberFormat - 用于指定数值的显示格式
 * @see JsonbNillable - 用于启用空值的序列化
 */
@SuppressWarnings({"unused", "WeakerAccess"})
public class PersonDTO {

    private int id;
    // 工号
    @JsonbProperty("工号")
    private String name;
    // 姓名
    @JsonbProperty("姓名")
    private String username;
    // 身份
    @JsonbProperty("身份")
    private String identity;
    // 部门
    @JsonbProperty("部门")
    private String department;
    // 邮件
    @JsonbProperty(value = "邮件", nillable = true)
    private String email;
    // 年龄
    @JsonbTransient
    private int age;
    // 注册日期
    @JsonbDateFormat("dd-MM-yyyy")
    @JsonbProperty("注册日期")
    private LocalDate registeredDate;
    // 薪水
    @JsonbProperty("薪水")
    private BigDecimal salary;

    // 为了使用jsonb,必须有一个空的默认构造方法
    public PersonDTO() {

    }

    public PersonDTO(String name, String username, String identity, String department, String email, int age, LocalDate registeredDate, BigDecimal salary) {
        this.name = name;
        this.username = username;
        this.identity = identity;
        this.department = department;
        this.email = email;
        this.age = age;
        this.registeredDate = registeredDate;
        this.salary = salary;
    }

    @JsonbNumberFormat(locale = "en_US", value = "#0.0")
    public BigDecimal getSalary() {
        return salary;
    }

    public void setSalary(BigDecimal salary) {
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getIdentity() {
        return identity;
    }

    public void setIdentity(String identity) {
        this.identity = identity;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public LocalDate getRegisteredDate() {
        return registeredDate;
    }

    public void setRegisteredDate(LocalDate registeredDate) {
        this.registeredDate = registeredDate;
    }
}